/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */

package com.elvis.music.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.elvis.music.R;
import com.elvis.music.model.Music;

public class MusicListAdapter extends BaseAdapter {

    private Context mContext;

    private List<Music> mListMusic;
    
    private int position;

    public MusicListAdapter(Context con, List<Music> listMusic) {
        mContext = con;
        mListMusic = listMusic;
    }
    
    public void setMusicIndicator(int position){
        this.position = position;
    }

    public int getCount() {
        return mListMusic.size();
    }

    public Object getItem(int position) {
        return mListMusic.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    private TextView lineItemDuration;

    private TextView lineItemName;

    private TextView lineItemDescription;

    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.lineitem, null);
        }
        lineItemDuration = (TextView) convertView.findViewById(R.id.LineItemDuration);
         //ImageView lineItemImage = (ImageView)
        // convertView.findViewById(R.id.LineItemImage);
        lineItemName = (TextView) convertView.findViewById(R.id.LineItemName);
        lineItemDescription = (TextView) convertView.findViewById(R.id.LineItemDescription);

         ImageView lineItemCheckImage = (ImageView)    convertView.findViewById(R.id.LineItemCheckImage);
         if(this.position==position)
             lineItemCheckImage.setImageResource(R.drawable.indicator_ic_mp_playing_list);
        lineItemDuration.setText(mListMusic.get(position).duration);
        lineItemDescription.setText(mListMusic.get(position).artist);
        lineItemName.setText(String.valueOf(position+1)+"、"+mListMusic.get(position).title);
        return convertView;
    }

}
